package com.example.myapplication2;

import android.view.View;
import android.widget.AdapterView;
import android.widget.Spinner;
import android.widget.Toast;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import com.example.myapplication2.Adapter.BaseAdapterDemo;

import java.util.ArrayList;
import java.util.HashMap;

public class BaseAdapterActivity extends AppCompatActivity implements AdapterView.OnItemSelectedListener {

    public static final String[] array={"Q","A","B"};
    public static final int[] ioc={R.color.black,R.color.teal_700,R.color.purple_200};

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_base_adapter);
        Spinner spinner = findViewById(R.id.Spinner_dropdown3);
        ArrayList<HashMap<String, Object>> list = new ArrayList<>();
        for (int k = 0; k < 30; k++) {
            for (int i = 0; i < array.length; i++) {
                HashMap<String, Object> hashMap = new HashMap<>();
                hashMap.put("ioc",ioc[i]);
                hashMap.put("text",array[i]+k);
                list.add(hashMap);
            }
        }
        //创建一个自定义适配器
        BaseAdapterDemo baseAdapterDemo = new BaseAdapterDemo(this,list);
        spinner.setAdapter(baseAdapterDemo);
        //默认选中
        spinner.setSelection(0);
        spinner.setOnItemSelectedListener(this);
    }

    @Override
    public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) {
        Toast.makeText(this,"array[i]",Toast.LENGTH_SHORT).show();
    }

    @Override
    public void onNothingSelected(AdapterView<?> adapterView) {

    }
}